<?php

namespace Admin\Controller;
use Think\Controller;

    class LoginController extends Controller {
       /**
        * 后台登录显示
        */
    public function index()
    {
        
        //  $m = M();
        // $data->table('bbs_user')->select();
		//  var_dump($m);
		
        $this -> display(); 
    }

    /**
     * 后台登录处理提交的方法
     */
    public function dologin()
    {
        //接收post传输的数据
        $uname = I('post.uname');
        $upass = I('post.upass');

        // var_dump($uname,$upass);
        
        // 通过 M 函数获取 User 模型对象 
        $users = M('user');
         $res = $users->where($where)->find();
        //    var_dump($res);die;
        $where = [
            'uname' => $uname,
            'upass' => $upass
        ];
        $res = $users->where($where)->find(); 
        //print_r($res);
		if($res['auth'] ==3){
            $this->success();
        }else{
            $this->error('非管理员禁止登陆',U('login/index'));
            
		}
		
        //判断登录是否成功 则保存session
        if(is_null($res)) {
            $this->error('用户名或密码错误');
        } else {
            session('adminInfo', $res); // 通过 session 函数保存 Session
            //var_dump($adminInfo);die;
            $this->redirect('Index/index');
		}
		
		
		
       
	}
	

    public function loginout()
    {
        session_destroy();
        $this->redirect('Login/index');
    }
    
}